<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>账户管理 - 棉花糖</title>
		<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/admin-lte@3.1.0/dist/css/adminlte.min.css" integrity="sha256-FQ+k0mIFfWXVTaW1arh3qKx8IXX5Bm5f6QG+0pkUjaE=" crossorigin>
		<link rel="preload" as="font" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.13.0/webfonts/fa-solid-900.woff2" crossorigin>
		<link rel="preload" as="font" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.13.0/webfonts/fa-regular-400.woff2" crossorigin>
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.13.0/css/all.min.css" integrity="sha256-h20CPZ0QyXlBuAw7A+KluUYx/3pK+c7lYEpqLTlxjYQ=" crossorigin>
		<link rel="stylesheet" href="https://cdn.bootcss.com/ionicons/2.0.1/css/ionicons.min.css">
	</head>
	<body class="hold-transition sidebar-mini">

		<div class="modal fade" id="done" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
			<div class="modal-dialog modal-dialog-centered">
				<div class="modal-content">
					<div class="modal-header">
						<h5 class="modal-title" id="donetitle">Loading...</h5>
						<button type="button" class="btn" data-bs-dismiss="modal" aria-label="Close">
							<i class="fa fa-times"></i>
						</button>
					</div>
					<div class="modal-body" id='donemsg'>
						Loading...
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" onclick="location.reload();">关闭</button>
					</div>
				</div>
			</div>
		</div>

		<div class="wrapper">

			<nav class="main-header navbar navbar-expand navbar-white navbar-light">
				<ul class="navbar-nav">
					<li class="nav-item">
						<a class="nav-link" data-widget="pushmenu" href="#" role="button">
							<i class="fas fa-bars"></i>
						</a>
					</li>
				</ul>

				<ul class="navbar-nav ml-auto">
					<li class="nav-item">
						<a class="nav-link" href="" role="button" onclick="logout()">
							<i class="fas fa-sign-out-alt"></i>
						</a>
					</li>
				</ul>
			</nav>


			<aside class="main-sidebar sidebar-dark-primary elevation-4">

				<a class="brand-link" style="text-align: center;">
					<span class="brand-text font-weight-light">棉花糖后台管理</span>
				</a>


				<div class="sidebar">

					<div class="user-panel mt-3 pb-3 mb-3 d-flex">
						<div class="image">
							<img src="https://gravatar.loli.net/avatar/" class="img-circle elevation-2" alt="User Image">
						</div>
						<div class="info">
							<a class='d-block'>
								<span id="usname">Loading...</span>
							</a>
						</div>
					</div>

					<nav class="mt-2">
						<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
							<li class="nav-header">设置</li>
							<li class="nav-item">
								<a href="../" class="nav-link">
									<i class="nav-icon fas fa-home"></i>
									<p>仪表盘</p>
								</a>
							</li>

							<li class="nav-item">
								<a href="../messages/" class="nav-link">
									<i class="nav-icon fas fa-list"></i>
									<p>语句列表</p>
								</a>
							</li>

							<li class="nav-item">
								<a href="./" class="nav-link active">
									<i class="nav-icon fas fa-user"></i>
									<p>账户管理</p>
								</a>
							</li>

							<li class="nav-item">
								<a href="../site/" class="nav-link">
									<i class="nav-icon fas fa-stream"></i>
									<p>站点设置</p>
								</a>
							</li>
							<div>
								<li class="nav-header">快捷链接</li>
								<li class="nav-item">
									<a href="../../" class="nav-link">
										<i class="nav-icon fas fa-home"></i>
										<p>主页</p>
									</a>
								</li>
								<li class="nav-item">
									<a href="../../read" class="nav-link">
										<i class="nav-icon fas fa-book"></i>
										<p>阅读棉花糖</p>
									</a>
								</li>
							</div>
						</ul>
					</nav>

				</div>

			</aside>


			<div class="content-wrapper">

				<div class="content-header">
					<div class="container-fluid">
						<div class="row mb-2">
							<div class="col-sm-6">
								<h1 class="m-0">账户设置</h1>
							</div>
							<div class="col-sm-6">
								<ol class="breadcrumb float-sm-right">
									<li class="breadcrumb-item">
										<a href="#">管理面板</a>
									</li>
									<li class="breadcrumb-item active">账户设置</li>
								</ol>
							</div>
						</div>
					</div>
				</div>

				<div class="content">
					<div class="container-fluid">
						<div class="card card-warning">
							<div class="card-header">
								<h3 class="card-title">
									更改密码
								</h3>
							</div>
							<div class="card-body">
								<div class="form-group">
									<label>原密码</label>
									<input type="password" class="form-control" name="oldpw" required="" autocomplete="current-password" id="oldpw">
								</div>

								<div class="form-group">
									<label>新密码</label>
									<input type="password" class="form-control" name="newpw" required="" autocomplete="new-password" id="newpw">
								</div>

								<div class="form-group">
									<label>确认密码</label>
									<input type="password" class="form-control" name="confirmpw" required="" autocomplete="new-password" id="confirmpw">
								</div>
								<div id="alert1"></div>
							</div>
							<div class="card-footer">
								<button class="btn btn-primary" onclick="changepw()">
									修改密码
								</button>
							</div>
						</div>


						<div class="card card-warning">
							<div class="card-header">
								<h3 class="card-title">
									更改用户名
								</h3>
							</div>
							<div class="card-body">
								<div class="form-group">
									<label>新用户名</label>
									<input type="text" class="form-control" name="newun" required="" minlength="8" maxlength="32" autocomplete="new-username" id="newun">
								</div>

								<div class="form-group">
									<label>确认用户名</label>
									<input type="text" class="form-control" name="confirmun" required="" minlength="8" maxlength="32" autocomplete="new-username" id="confirmun">
								</div>
								<div id="alert2"></div>
							</div>
							<div class="card-footer">
								<button class="btn btn-primary" onclick="changeun()">
									修改用户名
								</button>
							</div>
						</div>

					</div>
				</div>

			</div>

			<footer class="main-footer">
				<strong>Copyright &copy; 2021 <a href="https://i.lite.cafe" target="_blank">ImJingLan</a>.</strong> All rights reserved.
			</footer>
		</div>
		<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
		<script src="https://cdn.jsdelivr.net/npm/admin-lte@3.1.0/dist/js/adminlte.min.js"></script>
		<script src="../js/Y8ui.js"></script>
		<script>
			checklogin();
			            getuser();
		</script>
		<script>
			function logout()
			            {
			                $.ajax({
			                    type: "post",
			                    url: "../logout",
			                    data: {},
			                    async: false,
			                    success: function(a) {
			                    }
			                });
			                location.replace("../login");
			            }
			
			            function logout2()
			            {
			                $.ajax({
			                    type: "post",
			                    url: "../logout",
			                    data: {},
			                    async: false,
			                    success: function(a) {
			                    }
			                });
			            }
			
			            function changepw(){
			                $.ajax({
			                    type: "post",
			                    url: "./changepw.php",
			                    data: {oldpw:$('#oldpw').val() , newpw:$('#newpw').val() ,confirmpw : $('#confirmpw').val()},
			                    async: false,
			                    success: function(a) {
			                        json = JSON.parse(a);
			                        if(json['code'] == 1){
			                            $('#alert1').html('<div class="alert alert-warning" role="alert"><i class="icon fas fa-exclamation-triangle"></i>'+json['data']['msg']+'</div>');
			                        }
			                        if(json['code'] == 0){
			                            $('#alert1').html('');
			                            logout2();
			                            $('#donemsg').html(json['data']['msg']);
			                            $('#donetitle').html('修改成功');
			                            $('#done').modal('show');
			                        }
			                    }
			                });
			            }
			
			            function changeun(){
			                $.ajax({
			                    type: "post",
			                    url: "./changeun.php",
			                    data: {newun:$('#newun').val() ,confirmun : $('#confirmun').val()},
			                    async: false,
			                    success: function(a) {
			                        json = JSON.parse(a);
			                        if(json['code'] == 1){
			                            $('#alert2').html('<div class="alert alert-warning" role="alert"><i class="icon fas fa-exclamation-triangle"></i>'+json['data']['msg']+'</div>');
			                        }
			                        if(json['code'] == 0){
			                            $('#alert2').html('');
			                            logout2();
			                            $('#donemsg').html(json['data']['msg']);
			                            $('#donetitle').html('修改成功');
			                            $('#done').modal('show');
			                        }
			                    }
			                });
			            }
		</script>
	</body>
</html>